<?php
// $Header: /cvsroot/tsheet/timesheet.php/admin_report_all.php,v 1.5 2005/05/23 10:42:46 vexil Exp $

// Authenticate
require("class.AuthenticationManager.php");
require("class.CommandMenu.php");
if (!$authenticationManager->isLoggedIn() || !$authenticationManager->hasClearance(CLEARANCE_ADMINISTRATOR)) 
{
	Header("Location: login.php?redirect=$_SERVER[PHP_SELF]&clearanceRequired=Administrator");
	exit;
}

// Connect to database.
$dbh = dbConnect();
$contextUser = strtolower($_SESSION['contextUser']);

//load local vars from superglobals
$uid = isset($_REQUEST["uid"]) ? $_REQUEST["uid"]: 1;
$orderby = isset($_REQUEST["orderby"]) ? $_REQUEST["orderby"]: "username";
	
//define the command menu
include("timesheet_menu.inc");
   
// Calculate the previous month.
$next_month = $month + 1;
$next_year  = $year;
$prev_month = $month - 1;
$prev_year  = $year;

//rollover year forward
if (!checkdate($next_month, 1, $next_year)) {
	$next_month -= 12;
	$next_year ++;
}

//rollover year back
if (!checkdate($prev_month, 1, $prev_year)) {
    $prev_month += 12;
    $prev_year --;
}

?>
<html>
    <head>
        <title>Timesheet.php Report: All days this month</title>
        <?php include ("header.inc"); ?>
    </head>
    <body <?php include ("body.inc"); ?> >
    <?php include ("banner.inc"); ?>
    
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        	<tr>
        		<td width="100%" class="face_padding_cell">
        			<table width="100%" border="0">
        				<tr>
        					<td align="left" nowrap class="outer_table_heading">
        					    <?php echo date('F Y',mktime(0,0,0,$month,1,$year)) ?>
        					    </td>
        					<td align="right" nowrap>
        					    <?php print "<a href=\"$_SERVER[PHP_SELF]?uid=$uid&month=$prev_month&year=$prev_year\" class=\"outer_table_action\">Prev</a>&nbsp;";
        					    print "<a HREF=\"$_SERVER[PHP_SELF]?uid=$uid&month=$next_month&year=$next_year\" class=\"outer_table_action\">Next</a>"; ?>
        					</td>
        				</tr>
        			</table>
        	        <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="outer_table">
        	        	<tr>
        	        		<td>			
        	        			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_body">
        	        				<tr class="inner_table_head">
        	        					<td class="inner_table_column_heading">Client</b>
        	        					</td>
										<td class="inner_table_column_heading">Project title</b>
        	        					</td>
										<td class="inner_table_column_heading">Project leader</b>
										</td>
										<td class="inner_table_column_heading">Company</b>
        	        					</td>
        	        					<td class="inner_table_column_heading">Task name</b>
        	        					</td>	
                                        <td class="inner_table_column_heading">Task Manager</td>
                                        <td class="inner_table_column_heading">Related RnD Project</td>										
        	        				</tr>				
        <?php 
        	$query = "select distinct $PROJECT_TABLE.title, $PROJECT_TABLE.proj_id, $PROJECT_TABLE.proj_leader, $USER_TABLE.company, $TASK_TABLE.name, $TASK_TABLE.manager, $TASK_TABLE.task_id, $CLIENT_TABLE.organisation, $TASK_TABLE.source_project, $TASK_TABLE.target_project ".
        		     "FROM            $USER_TABLE, $PROJECT_TABLE, $TASK_TABLE, $ASSIGNMENTS_TABLE, $TASK_ASSIGNMENTS_TABLE, $CLIENT_TABLE ".
					 "WHERE           $ASSIGNMENTS_TABLE.proj_id = $PROJECT_TABLE.proj_id ".
					 "AND             $TASK_ASSIGNMENTS_TABLE.task_id = $TASK_TABLE.task_id ".
                     "AND	 		  $CLIENT_TABLE.client_id = $PROJECT_TABLE.client_id ".
        		     "AND             ($PROJECT_TABLE.title = $TASK_TABLE.source_project OR $PROJECT_TABLE.title = $TASK_TABLE.target_project) ".
					 "AND             $ASSIGNMENTS_TABLE.username = $USER_TABLE.username ".
					 "AND             $PROJECT_TABLE.proj_leader = $USER_TABLE.username ".
                     "AND             $USER_TABLE.username ".
					 "NOT IN          ('admin','guest') ".
 					 "ORDER BY        $CLIENT_TABLE.organisation, $PROJECT_TABLE.title, $TASK_TABLE.name";
        
        	list ($qh,$num) = dbQuery($query);
        	$last_username = "";
        
        	if ($num == 0) {
        		print "	<tr>\n";
        		print "		<td align=\"center\">\n";
        		print "			<i><br>No Days recorded.<br><br></i>\n";
        		print "		</td>\n";
        		print "	</tr>\n";
        	}
        	else {
        		while ($name_data = dbResult($qh)) {
				
                    $client         = stripslashes($name_data["organisation"]);
                    $projectTitle   = stripslashes($name_data["title"]);
					$projectLeader  = stripslashes($name_data["proj_leader"]);
					$company        = $name_data["company"];
                    $taskName       = stripslashes($name_data["name"]);
					$manager        = $name_data["manager"];
					$source_project = stripslashes($name_data["source_project"]);
					$target_project = stripslashes($name_data["target_project"]);
					
        			print "<td class=\"calendar_cell_disabled_right\"><a href=\"javascript:void(0)\" ONCLICK=window.open(\"proj_info.php?proj_id=$name_data[proj_id]\",\"Info\",\"location=0,directories=no,status=no,menubar=no,resizable=1,scrollbar=yes,width=580,height=200\") class=\"outer_table_action\">$client</A></TD>\n";
        			print "<td class=\"calendar_cell_disabled_right\"><a href=\"javascript:void(0)\" ONCLICK=window.open(\"proj_info.php?proj_id=$name_data[proj_id]\",\"Info\",\"location=0,directories=no,status=no,menubar=no,resizable=1,scrollbar=yes,width=580,height=200\") class=\"outer_table_action\">$projectTitle</A></TD>\n";
        			print "<td class=\"calendar_cell_disabled_right\">$projectLeader</TD>\n";
					print "<td class=\"calendar_cell_disabled_right\">$company</TD>\n";
        			print "<td class=\"calendar_cell_disabled_right\"><a href=\"javascript:void(0)\" ONCLICK=window.open(\"task_info.php?proj_id=$name_data[proj_id]&task_id=$name_data[task_id]\",\"TaskInfo\",\"location=0,directories=no,status=no,scrollbar=yes,menubar=no,resizable=1,width=580,height=220\")>$taskName</A></TD>\n";
        	        print "<td class=\"calendar_cell_disabled_right\">$manager</TD>\n";
					if($source_project == $target_project)
					{
					    print "<td class=\"calendar_cell_disabled_right\"> </TD>\n";
					} else {
					    print "<td class=\"calendar_cell_disabled_right\">$source_project</TD>\n";
					}
        	        print "</tr>\n";
        	}
        }
        ?>
        	        			</TABLE>
        	        		</td>
        	        	</tr>
        	        </table>
        		</td>
        	</tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
            	<td align="center" nowrap>
            	   <a href="admin_report_all_projects_and_tasks_dowload_xls.php?month=<?php print $month; ?>&year=<?php print $year; ?>&query=<?php print $query; ?>&mode=monthly">
        		       <input name="downloadButton" type="button" id="downloadButton" value="Download" onClick="DownloadAdminReportAll()"> </input> 
        		   </a>
        		   <br><br>
            	</td>
            </tr>
        </table> 
        <?php include ("footer.inc");?>
    </BODY>
</HTML>


	
 